home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctjja86.arc
/
LISTREV.PRO
< prev
next >
Wrap
Text File
|
1985-11-13
|
609b
|
24 lines
/* List reversal benchmark */
/* Number of logical inferences = (N**2 + N)/2 + N + 1, */
/* where N is the number of elements in the list. */
reverse([],[]).
reverse([X|Y],Z) :- reverse(Y,Y1), append(Y1,[X],Z).
append([],X,X).
append([X|Y],Z,[X|W]) :- append(Y,Z,W).
/* To perform the test, generate a 30-element list */
/* and then reverse it (446 logical inferences). */
generate(0,[]).
generate(N,[N|Y]) :- M is N-1, generate(M,Y).
test :- generate(30,X),
write('Start...'),
nl,
reverse(X,Y),
write(Y),
nl,
nl.